package com.vallis.lottery.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;


import com.vallis.lottery.domain.SnNumber;
import com.vallis.lottery.service.ISnNumberService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vallis.common.annotation.Log;
import com.vallis.common.core.controller.BaseController;
import com.vallis.common.core.domain.AjaxResult;
import com.vallis.common.enums.BusinessType;

import com.vallis.common.utils.poi.ExcelUtil;
import com.vallis.common.core.page.TableDataInfo;

/**
 * 邀请码Controller
 *
 * @author vallis
 * @date 2022-08-10
 */
@RestController
@RequestMapping("/system/number")
public class SnNumberController extends BaseController
{
    @Autowired
    private ISnNumberService snNumberService;

    /**
     * 查询邀请码列表
     */
    @PreAuthorize("@ss.hasPermi('system:number:list')")
    @GetMapping("/list")
    public TableDataInfo list(SnNumber snNumber)
    {
        startPage();
        List<SnNumber> list = snNumberService.selectSnNumberList(snNumber);
        return getDataTable(list);
    }

    /**
     * 导出邀请码列表
     */
    @PreAuthorize("@ss.hasPermi('system:number:export')")
    @Log(title = "邀请码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SnNumber snNumber)
    {
        List<SnNumber> list = snNumberService.selectSnNumberList(snNumber);
        ExcelUtil<SnNumber> util = new ExcelUtil<SnNumber>(SnNumber.class);
        util.exportExcel(response, list, "邀请码数据");
    }

    /**
     * 获取邀请码详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:number:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(snNumberService.getById(id));
    }

    /**
     * 新增邀请码
     */
    @PreAuthorize("@ss.hasPermi('system:number:add')")
    @Log(title = "邀请码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SnNumber snNumber) {
        return toAjax(snNumberService.save(snNumber));
    }

    /**
     * 修改邀请码
     */
    @PreAuthorize("@ss.hasPermi('system:number:edit')")
    @Log(title = "邀请码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SnNumber snNumber) {
        return toAjax(snNumberService.updateById(snNumber));
    }

    /**
     * 删除邀请码
     */
    @PreAuthorize("@ss.hasPermi('system:number:remove')")
    @Log(title = "邀请码", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(snNumberService.removeByIds(Arrays.asList(ids)));
    }
}
